Working with Project Tree Groups (Creating, Expanding, Locking)

This example demonstrates how to create a Tree group, expand it to view all its children, and lock it. This example uses the IProjectTree80 (CreateGroup, ExpandGroup, CreateLockedGroup), ICreator80 (CreateLabelStyle, CreateTextLabel), ILabelStyle80(LineToGroundType, TextColor), and INavigate80 (FlyTo) properties and methods.

 

private void CreateHierarchy()

        {

            try

            {

                var SGWorld = new SGWorld80();

                // create group

                var newEngland = SGWorld.ProjectTree.CreateGroup("New England");

                var states = SGWorld.ProjectTree.CreateGroup("States", newEngland);

                // create 5 labels inside group

                var stateLabelStyle = SGWorld.Creator.CreateLabelStyle(SGLabelStyle.LS_DEFAULT);

                stateLabelStyle.LineToGround = true;

                stateLabelStyle.TextColor.FromARGBColor((uint)Color.Beige.ToArgb());

                var Vermont = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-72.75206, 43.91127, 80000.0, 0, 0.0, 0, -85, 800000.0), "Vermont", stateLabelStyle, states, "Vermont");

                var Maine = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-69.40414, 45.12594, 80000.0, 0, 0.0, 0, -85, 800000.0), "Maine", stateLabelStyle, states, "Maine");

                var Massachusetts = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-71.88455, 42.34216, 80000.0, 0, 0.0, 0, -85, 800000.0), "Massachusetts", stateLabelStyle, states, "Massachusetts");

                var RhodeIsland = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-71.57173, 41.62953, 80000.0, 0, 0.0, 0, -85, 800000.0), "Rhode Island", stateLabelStyle, states, "Rhode Island");

                var Connecticut = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-72.64295, 41.57912, 80000.0, 0, 0.0, 0, -85, 800000.0), "Connecticut", stateLabelStyle, states, "Connecticut");

                // expand the group

                SGWorld.ProjectTree.ExpandGroup(newEngland, true);

                // fly to first label

                SGWorld.Navigate.FlyTo(Vermont, ActionCode.AC_FLYTO);

                MessageBox.Show("Created group and 5 labels in it. Click Ok to continue");

                var places = SGWorld.ProjectTree.CreateLockedGroup("Places", newEngland);

                var placeLabelStyle = SGWorld.Creator.CreateLabelStyle(SGLabelStyle.LS_DEFAULT);

                placeLabelStyle.LineToGround = true;

                placeLabelStyle.TextColor.FromARGBColor((uint)Color.Cyan.ToArgb());

                var LakeChamplain = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-73.333333, 44.533333, 160000.0, 0, 0.0, 0, -85, 800000.0), "Lake Champlain", placeLabelStyle, places, "Lake Champlain");

                var Windsor = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-72.401111, 43.477167, 160000.0, 0, 0.0, 0, -85, 800000.0), "Windsor, Vermont", placeLabelStyle, places, "Windsor, Vermont");

                var NewHaven = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-72.923611, 41.31, 160000.0, 0, 0.0, 0, -85, 800000.0), "New Haven, Connecticut", placeLabelStyle, places, "New Haven, Connecticut");

                var Hartford = SGWorld.Creator.CreateTextLabel(SGWorld.Creator.CreatePosition(-72.677, 41.767, 160000.0, 0, 0.0, 0, -85, 800000.0), "Hartford, Connecticut", placeLabelStyle, places, "Hartford, Connecticut");

                MessageBox.Show("Created locked group 'Places' and 4 labels in it. You may use right click menu of the group to unlock it and edit its content");

            }

            catch (Exception ex)

            {

                MessageBox.Show("Unexpected error: " + ex.Message);

            }

        }